// components/active-device/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    code:''
  },
  /**
   * 组件的方法列表
   */
  methods: {
    activeDevice(){
      if(!this.data.code){
        return
      }
      wx.request({
        url: getApp().globalData.baseUrl + '/api/bindUserDoctor',
        method:'POST',
        header:{
          'token':wx.getStorageSync('token'),
          'Cookie':wx.getStorageSync('cookie')
        },
        data:{
          invite_code:this.data.code
        },
        success:(res) =>{
          let result = res.data
          if(result.statusCode !== 0){
            return wx.showToast({
              title: result.msg,
              icon:'error',
              duration:1000
            })
          }
          
          wx.request({
            url: getApp().globalData.baseUrl + '/api/getUserInfoByToken',
            method:'POST',
            header:{
              'token':wx.getStorageSync('token'),
              'Cookie':wx.getStorageSync('cookie')
            },
            data:{
              
            },
            success:(res) =>{
              let result = res.data
              if(result.statusCode !== 0){
                return wx.showToast({
                  title: result.msg,
                  icon:'error',
                  duration:1000
                })
              }
              wx.setStorageSync('loginInfo', result.data)
              this.triggerEvent('closemask')
            },
            fail:(res) =>{
              wx.showToast({
                title: '获取失败',
              })
            }
          })
        },
        fail:(res) =>{
          wx.showToast({
            title: '验证失败',
          })
        }
      })
    }
  }
})
